package com.smart.community.common.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

import javax.annotation.Resource;

/**
 * @author zhangwei
 */
@Configuration
@EnableOpenApi
public class SwaggerConfig {
    @Resource
    private SwaggerProperties swaggerProperties;

    @Bean
    public Docket docket(ApiInfo apiInfo) {
        return new Docket(DocumentationType.OAS_30).apiInfo(apiInfo)
                //
                .groupName(swaggerProperties.getGroupName())
                //
                .select()
                //
                .apis(RequestHandlerSelectors.basePackage(swaggerProperties.getBasePackage()))
                //
                .paths(PathSelectors.any())
                //
                .build();
    }

    @Bean
    public ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                //
                .title(swaggerProperties.getTitle())
                //
                .description(swaggerProperties.getDescription())
                //
                .version(swaggerProperties.getVersion())
                //
                .contact(new Contact(swaggerProperties.getName(), swaggerProperties.getUrl(), swaggerProperties.getEmail()))
                //
                .build();
    }
}
